<%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@include file="../WEB-INF/jspf/controlesessao.jspf"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Lista Salas</title>
        <script type="text/javascript" src="../js/jquery.js" ></script>
        <script type="text/javascript" src="../js/jquery.validate.js"></script>
        <script type="text/javascript" src="../js/jquery.tablescroll.js"></script>
        <script type="text/javascript" src="../js/forms.js"></script>
        <script type="text/javascript" src="../js/jquery-ui-1.8.2.custom.min.js" ></script>
        <link rel="stylesheet" href="../css/ui-lightness/jquery-ui-1.8.2.custom.css">
    <link rel="stylesheet" href="../css/forms.css"></head>

    <body>
        <div id="formulario">
            <h1>Listar Salas</h1>
            <form method="post">
                <p><label class="lbInput">Unidade</label>
                    <sql:query var="queryUnidade" dataSource="jdbc/dbo_MicrosoftSQLServer">
                        SELECT  * FROM Unidades
                        where situacao_unidade='A'
                    </sql:query>
                    <select name="id_unidade" onchange="submit()">
                        <option value="">Todos</option>
                        <c:forEach var="unidade" items="${queryUnidade.rows}">
                            <option value="${unidade.id_unidade}" ${unidade.id_unidade==param.id_unidade?'selected':''}>${unidade.desc_unidade}</option>
                        </c:forEach>
                    </select>
                </p>
                <p><label class="lbInput">Tipo da Sala</label>
                    <sql:query var="queryTipo" dataSource="jdbc/dbo_MicrosoftSQLServer">
                        SELECT  * FROM tiposalas
                        where situacao_tiposala='A'
                    </sql:query>
                    <select name="id_tiposala" onchange="submit()" >
                        <option value="">Todos</option>
                        <c:forEach var="tipo" items="${queryTipo.rows}">
                            <option value="${tipo.id_tiposala}" ${tipo.id_tiposala==param.id_tiposala?'selected':''}>${tipo.desc_tiposala}</option>
                        </c:forEach>
                    </select>
                </p>
            <input type="hidden" id="token" name="token" value="${sessionScope.token}" /> </form>

            <sql:query var="query" dataSource="jdbc/dbo_MicrosoftSQLServer">
                SELECT  salas.*, desc_unidade,desc_tiposala FROM Salas
                inner join tiposalas on salas.id_tiposala=tiposalas.id_tiposala
                inner join unidades on unidades.id_unidade=salas.id_unidade
                where 1=1
                <c:if test="${!empty param.id_tiposala}">
                    and salas.id_tiposala=?
                    <sql:param value="${param.id_tiposala}"/>
                </c:if>
                <c:if test="${!empty param.id_unidade}">
                    and salas.id_unidade=?
                    <sql:param value="${param.id_unidade}"/>
                </c:if>
                order by desc_sala
            </sql:query>
            <br>
            <br>
            <a href="fm_new_Salas.jsp?token=${sessionScope.token}">Incluir nova sala </a>
            <table cellspacing="0" width="100%">  <thead>
                    <th>Tipo</th>
                    <th>Unidade</th>
                    <th>Sala</th>
                    <th>Capacidade</th>
                </thead>
                <tfoot>
                    <tr>
                        <td colspan="5">
                            ${query.rowCount} registros encontrados
                        </td>
                    </tr>
                </tfoot>
                <c:forEach var="row" items="${query.rows}">
                    <tr>
                        <td>${row.desc_tiposala}</td>
                        <td>${row.desc_unidade}</td>
                        <td><a href="fm_update_Salas.jsp?token=${sessionScope.token}&chave=${row.id_sala}">${row.desc_sala}</a></td>
                        <td>${row.lotacao_sala}</td>

                    </tr></c:forEach>
                </table>
                <script>
                    jQuery(document).ready(function($)
                    {
                        $('table').tableScroll({height:400});

                    });
                </script>
            </div>
        </body>
    </html>
